﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using ClassLibrary1.Model;
namespace ClassLibrary1
{
    public class Class1
    {
        [CommandMethod("GetLines")]
        public void GetLines()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            ed.WriteMessage("\nhello!");
            PromptSelectionResult res = ed.GetSelection();
            List<Line> lines =  new List<Line>();
            if(res.Status == PromptStatus.OK )
            {
                SelectionSet selSet = res.Value;
                using (Transaction trans = doc.TransactionManager.StartTransaction())
                {
                    foreach (SelectedObject selObj in selSet)
                    {
                        if (selObj != null)
                        {
                            Line line = trans.GetObject(selObj.ObjectId, OpenMode.ForRead) as Line;
                            if (line != null)
                            {
                                // 在此处添加处理线条的逻辑，例如输出线条的起点和终点
                                //ed.WriteMessage($"\n线条起点: {line.StartPoint}, 终点: {line.EndPoint}");
                                lines.Add(line);
                            }
                        }
                    }
                    trans.Commit();
                }
            }
            ed.WriteMessage($"\n{lines.Count}");
            Model.Graph graph = new Model.Graph(lines);

        }
    }
}
